package ordinaryArray;

/*
 *@description 最长公共前缀
 *@author hkfan
 *@version 1.0
 *@create 2025/5/27 09:51
 */
public class LeetCode_14 {
    public String longestCommonPrefix(String[] strs) {
        String res = "";
        if (strs.length==1){
            return strs[0];
        }
        for (int i = 1; i <= strs[0].length(); i++) {
            String str = strs[0].substring(0,i);
            Boolean flag = false;
            for (int j = 1; j < strs.length; j++) {
                if (i>strs[j].length()||!str.equals(strs[j].substring(0,i))){
                    flag=true;
                    break;
                }
            }
            if (flag){
                break;
            }
            res = str;
        }
        return res;
    }
}
